//
//  XMVisitorViewController.swift
//  XMWeimo
//
//  Created by ios001 on 16/7/19.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class XMVisitorViewController: UIViewController {

    // 判断用户是否登录
//    var isLogin: Bool = false
    var isLogin: Bool = XMUserAccountViewModel.sharedTools.isLogin

    // 访客视图view
    var visitorView: XMVisitorView?
    
    // MARK: - 监听方法
    @objc private func loginClick() {
        // 加载授权界面
        let oauthVC = XMOAuthViewController()
        presentViewController(UINavigationController(rootViewController: oauthVC), animated: true, completion: nil)
    }
    
    override func loadView() {
        isLogin ? (view = tableView) : setupVisitorView()
        print(isLogin)
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

    }
    
    func setupVisitorView() {
        visitorView = XMVisitorView()
        visitorView?.closure = { [weak self] in
            self?.loginClick()
        }
        view = visitorView
        setupNav()
    }
    
    // MARK: - 设置导航控制器
    func setupNav() {
        navigationItem.leftBarButtonItem = XMBarButtonItem(title: "登录", target: self, action: "loginClick")
        navigationItem.rightBarButtonItem = XMBarButtonItem(title: "注册", target: self, action: "loginClick")
    }
    
    
    // MARK: - 懒加载控件
    lazy var tableView: UITableView = UITableView()

}
